home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / Spinner.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  3.7 KB  |  196 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Event;
  7. import java.awt.FlowLayout;
  8. import java.awt.LayoutManager;
  9. import java.awt.Panel;
  10. import java.awt.TextField;
  11.  
  12. public abstract class Spinner extends Panel implements Orientation {
  13.    public final int ORIENTATION_DEFAULT;
  14.    protected int min;
  15.    protected int max;
  16.    protected int current;
  17.    protected String text;
  18.    protected int textWidth;
  19.    protected TextField textField;
  20.    protected int increment = 1;
  21.    private SpinButtonPanel buttons;
  22.    private boolean editable;
  23.    private boolean wrappable;
  24.    private int orientation;
  25.    private boolean textFieldAdded = false;
  26.  
  27.    protected Spinner() {
  28.       this.setWrappable(false);
  29.       this.setMin(0);
  30.       this.setMax(0);
  31.       this.setCurrent(0);
  32.       this.setOrientation(0);
  33.       this.textWidth = -1;
  34.       super.setLayout(new FlowLayout());
  35.    }
  36.  
  37.    public void setEditable(boolean var1) {
  38.       this.editable = var1;
  39.       if (this.textFieldAdded) {
  40.          this.setEditable();
  41.       }
  42.  
  43.    }
  44.  
  45.    public boolean getEditable() {
  46.       return this.editable;
  47.    }
  48.  
  49.    public void setWrappable(boolean var1) {
  50.       this.wrappable = var1;
  51.    }
  52.  
  53.    public boolean getWrappable() {
  54.       return this.wrappable;
  55.    }
  56.  
  57.    public void setMin(int var1) {
  58.       this.min = var1;
  59.    }
  60.  
  61.    public int getMin() {
  62.       return this.min;
  63.    }
  64.  
  65.    public void setMax(int var1) {
  66.       this.max = var1;
  67.    }
  68.  
  69.    public int getMax() {
  70.       return this.max;
  71.    }
  72.  
  73.    public void setCurrent(int var1) {
  74.       this.current = var1;
  75.       this.updateText();
  76.    }
  77.  
  78.    public int getCurrent() {
  79.       return this.current;
  80.    }
  81.  
  82.    public void setOrientation(int var1) {
  83.       this.orientation = var1;
  84.       if (this.buttons != null) {
  85.          ((Container)this).remove(this.buttons);
  86.       }
  87.  
  88.       switch (this.orientation) {
  89.          case 0:
  90.             this.buttons = new VerticalSpinButtonPanel();
  91.             break;
  92.          case 1:
  93.             this.buttons = new HorizontalSpinButtonPanel();
  94.       }
  95.  
  96.       if (this.textFieldAdded) {
  97.          this.setStyle();
  98.       }
  99.  
  100.    }
  101.  
  102.    private void setStyle() {
  103.       ((Container)this).add(this.buttons);
  104.    }
  105.  
  106.    public int getOrientation() {
  107.       return this.orientation;
  108.    }
  109.  
  110.    public void setNotifyWhilePressed(boolean var1) {
  111.       this.buttons.setNotifyWhilePressed(var1);
  112.    }
  113.  
  114.    public boolean getNotifyWhilePressed() {
  115.       return this.buttons.getNotifyWhilePressed();
  116.    }
  117.  
  118.    public void setDelay(int var1) {
  119.       this.buttons.setDelay(var1);
  120.    }
  121.  
  122.    public int getDelay() {
  123.       return this.buttons.getDelay();
  124.    }
  125.  
  126.    public boolean handleEvent(Event var1) {
  127.       switch (var1.id) {
  128.          case 603:
  129.             this.scrollUp();
  130.             ((Component)this).postEvent(new Event(this, 1001, (Object)null));
  131.             break;
  132.          case 604:
  133.             this.scrollDown();
  134.             ((Component)this).postEvent(new Event(this, 1001, (Object)null));
  135.       }
  136.  
  137.       return super.handleEvent(var1);
  138.    }
  139.  
  140.    private void setEditable() {
  141.       this.textField.setEditable(this.editable);
  142.    }
  143.  
  144.    public void addNotify() {
  145.       super.addNotify();
  146.       if (!this.textFieldAdded) {
  147.          this.textField = new TextField(this.textWidth > 0 ? this.textWidth - 1 : 10);
  148.          this.textField.setBackground(Color.white);
  149.          ((Container)this).add(this.textField);
  150.          this.textFieldAdded = true;
  151.       }
  152.  
  153.       this.setEditable();
  154.       this.setStyle();
  155.       this.updateText();
  156.    }
  157.  
  158.    protected void scrollUp() {
  159.       this.current += this.increment;
  160.       if (this.current > this.max) {
  161.          if (this.wrappable) {
  162.             this.current = this.min;
  163.          } else {
  164.             this.current = this.max;
  165.          }
  166.       }
  167.  
  168.       this.updateText();
  169.    }
  170.  
  171.    protected void scrollDown() {
  172.       this.current -= this.increment;
  173.       if (this.current < this.min) {
  174.          if (this.wrappable) {
  175.             this.current = this.max;
  176.          } else {
  177.             this.current = this.min;
  178.          }
  179.       }
  180.  
  181.       this.updateText();
  182.    }
  183.  
  184.    protected void updateText() {
  185.       if (this.textFieldAdded) {
  186.          this.textField.setText(this.getCurrentText());
  187.       }
  188.  
  189.    }
  190.  
  191.    protected abstract String getCurrentText();
  192.  
  193.    public void setLayout(LayoutManager var1) {
  194.    }
  195. }
  196.